package com.leolian.spring01.aop.schema.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Component(value="genericAspect")
public class GenericAspect {
	/**
	 * 前置通知
	 */
	public void before(){
		System.out.println("GenericAspect before ...");
	}
	/**
	 * 返回通知
	 */
	public void afterReturning(){
		System.out.println("GenericAspect After-Returning ...");
	}
	/**
	 * 异常通知
	 */
	public void afterThrowing(){
		System.out.println("GenericAspect After-Throwing ...");
	}
	/**
	 * 后置通知
	 */
	public void after(){
		System.out.println("GenericAspect after ...");
	}
	/**
	 * 环绕通知
	 */
	public void around(ProceedingJoinPoint pjp){
		Object obj = null;
		try{
			System.out.println("GenericAspect around-1 ...");
			obj = pjp.proceed();
			System.out.println("GenericAspect around-2 ...");
		}catch(Throwable e){
			e.printStackTrace();
		}
	}
	/**
	 * 带参数的环绕通知
	 */
	public void aroundInit(ProceedingJoinPoint pjp,String name,int age){
		Object obj = null;
		try{
			System.out.println("GenericAspect aroundInit - 1; name="+name+",age"+age);
			obj = pjp.proceed();
			System.out.println("GenericAspect aroundInit - 2; name="+name+",age"+age);
		}catch(Throwable e){
			e.printStackTrace();
		}
	}
}
